package tjs.study.notes.dotest;

import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;

import java.io.File;
import java.io.FileOutputStream;

@ComponentScan(excludeFilters = {
        @ComponentScan.Filter(type = FilterType.REGEX, pattern = "tjs.study.notes.dotest.mongo.*")
})
@SpringBootApplication(
        exclude = {RedisAutoConfiguration.class, RedissonAutoConfiguration.class, MongoAutoConfiguration.class})
public class TjsStudyNotesApplication {
    public static final String work_space_pre = new File("").getAbsolutePath() + "/tjs-study-notes/tjs-study-dotest";
    public static final String work_space_classes = work_space_pre + "/target/classes";
    public static final String work_space = work_space_pre +
            "/src/main/java/tjs/study/notes/dotest";

    //将class文件存在磁盘
    public static void writeClassToDisk(String className, byte[] data) {
        try {
            String fileName = work_space_pre + "/src/main/java/" + className.replaceAll("\\.", "/") + ".java";
            System.out.println(fileName);
            File file = new File(fileName);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(data);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(TjsStudyNotesApplication.class, args);
    }

}
